#include "Player.h"
#include "DarkGDK.h"
#define  Key_W 17
#define  Key_S 31

int Player::GetPosX(void)
{

return dbCameraPositionX();

}

int Player::GetPosY(void)
{

return dbCameraPositionY();

}

int Player::GetPosZ(void)
{

return dbCameraPositionZ();

}

void Player::MoveTo(int X, int Y, int Z)
{

dbPositionCamera(X,Y,Z);

} 

float fCameraAngleX = 0;
float fCameraAngleY = 0;

void Player::Move(void)
{
	if (dbKeyState(Key_W) == 1){
       dbMoveCamera(5);
	}
	if (dbKeyState(Key_S) == 1){
	   dbMoveCamera(-5);
	}

		fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
		fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );
        
		// rotate camera and player model
		dbXRotateCamera ( fCameraAngleX );
		dbYRotateCamera ( fCameraAngleY );
        dbPositionObject(80000,dbCameraPositionX(),0,dbCameraPositionZ());
}

void Player::SnapToTerrain( int TileX, int TileZ, int Variation)
{
	float heightofcam = dbGetGroundHeight ( 1, dbCameraPositionX(),dbCameraPositionZ()  );
	//dbCurveValue ( heightofcam, dbGetMatrixHeight (1, TileX, TileZ)+300, 5 );
dbPositionCamera(dbCameraPositionX(),heightofcam+Variation,dbCameraPositionZ());



}

void Player::Debug(int X, int Y, int Z)
	{  

	
		// Display X PlayerTile
        char x [ 256 ] = "";
		strcpy ( x, "Inventory: Wood = " );
		strcat ( x, dbStr ( X ) );
		dbText ( dbScreenWidth ( ) - 20 - dbTextWidth ( x ), dbScreenHeight ( ) - 60, x );
       
		// Display Z Player Tile
		char y [ 256 ] = "";
		strcpy ( y, "Inventory: Iron =" );
		strcat ( y, dbStr ( Y ) );
		dbText ( dbScreenWidth ( ) - 20 - dbTextWidth ( y ), dbScreenHeight ( ) - 80, y );
      
		// Display dbMouseClick(); Status.
		char z [ 256 ] = "";
		strcpy ( z, "(Disabled)Inventory: Stone =" );
		strcat ( z, dbStr ( Z ) );
		dbText ( dbScreenWidth ( ) - 20 - dbTextWidth ( z ), dbScreenHeight ( ) - 100, z );
	
	}


Player::Player(int PlayerID)
{
ID = PlayerID;
dbSetCameraRange(1,30000);
}

Player::~Player()
{
}

